import {setToken} from '@/utils'
import { requst } from '@/utils'
import { ClearToken } from '@/utils'
export const login = (mobile, code) => {
  return async (dispatch) => {
 const res=  await requst.post(
      '/authorizations',
       {mobile,code}
    )
    //将获取的token值存储到redux中
    dispatch({
      type: 'login/token',
      payload:res.data.data.token
    })
    //将获取的token存入本地存储中
    setToken(res.data.data.token)
  }
}
//清除token
export const loginout = () => {
  return (dispatch) => {
    ClearToken()
    dispatch({type:'login/out'})
    dispatch({type:'login/user'})
  }
}